# -*- coding:utf8 -*-
"""
异常后重试
"""
from tenacity import retry


@retry
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)


from tenacity import retry, stop_after_attempt


@retry(stop=stop_after_attempt(3))
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)


from tenacity import retry, wait_fixed
@retry(wait=wait_fixed(5))
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)


from tenacity import retry, wait_exponential


@retry(wait=wait_exponential(multiplier=1, max=10)) # 重试时间间隔满足：2^n * multiplier, n为重试次数，但最多间隔10秒
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)


from tenacity import retry, retry_if_exception_type
from json.decoder import JSONDecodeError


@retry(retry=retry_if_exception_type(JSONDecodeError))
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)


from tenacity import retry, retry_if_exception_type, wait_fixed, stop_after_attempt
from json.decoder import JSONDecodeError


@retry(retry=retry_if_exception_type(JSONDecodeError), wait=wait_fixed(5), stop=stop_after_attempt(3))
def extract(url):
    info_json = requests.get(url).content.decode()
    info_dict = json.loads(info_json)
    data = info_dict['data']
    save(data)
